<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title></title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <link rel="shortcut icon" href="/favicon.ico">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm.min.css">
    <link rel="stylesheet" href="//g.alicdn.com/msui/sm/0.6.2/css/sm-extend.min.css">

    <style>
        *{
            margin:0;
            padding:0;
        }
        .xnav{
            width:100%;
            position:fixed;
            bottom:0;

        }
        .xnav ul li{
            float:left;
            height:2.5rem;
            width:32%;
            line-height: 2.5rem;
            list-style: none;
            background: #fff;
            text-align: center;
            border-top:1px solid #efeff4;
            color:#fff;
        }
        .xnav ul li:nth-of-type(-n+3){
            width:12%;
        }
        .xnav ul li:nth-of-type(4){
             background:#ff9600;
         }
        .xnav ul li:nth-of-type(5){
            background:#e4393c;
        }
        #ptitle{
            padding:0.4rem;
            font-size:14px;
            color: #051B28
        }
        #pricediv{
            color:#FF0036;
            font-size:20px;
            font-weight:400;
            padding-left:0.4rem;
        }

    </style>

</head>
<body>
<div class="page-group">
    <div class="page page-current">
        <!-- 你的html代码 -->
        <img src="" id="mainpic" width="100%" />
        <div id="ptitle"></div>
        <div id="pricediv"><sapn class="price-symbol">&yen;</sapn><span id="pprice"></span></div>
        <div class="xnav">
            <ul>
                <li><img src="images/55.png" style="width:1rem"></li>
                <li><img src="images/555.png" style="width:1rem"></li>
                <li><img src="images/55.png" style="width:1rem"></li>
                <li onclick="addShopCar()">加入购物车</li>
                <li onclick="car()">购物车</li>
            </ul>
        </div>
    </div>
</div>
    <script type='text/javascript' src='//g.alicdn.com/sj/lib/zepto/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='//g.alicdn.com/msui/sm/0.6.2/js/sm-extend.min.js' charset='utf-8'></script>
<script>
    var p;
    function car(){
        location="cart.html";
    }


    setItemPageTitle();
    function setItemPageTitle(){
        //取出当前商品
        var s = localStorage.getItem("currentP");
        p = JSON.parse(s);
        console.log(p);
        $("title").html(p.raw_title+"_歌瑞森");
    }
    //确定页面内容

    setItemPageContent();

      function setItemPageContent(){
          $("#mainpic").attr("src",p.pic_url);
          $("#ptitle").html(p.title);
          $("#pprice").html(p.view_price);
      }
      //加入购物车
      function addShopCar(){
          var product = {
              title:p.title,
              price:p.view_price,
              count:"1",
              pic:p.pic_url,
              nid:p.nid
          };
          //从本地存储中取出购物车对象
          var shopCar = JSON.parse(localStorage.getItem("shopCar"));
          if(!shopCar) {
              var shopCar = [];
              shopCar.push(product);
          }else{
              var isFind = false;
              for(var i=0;i<shopCar.length;i++){
                  if(shopCar[i].nid == p.nid){
                      shopCar[i].count++;
                      isFind = true;
                      break;
                  }
              }
              if(!isFind){
                  shopCar.push(product);
              }
          }
          localStorage.setItem("shopCar",JSON.stringify(shopCar));
          $.toast("加入成功！");
      }

</script>
</body>
</html>